package com.bluesky.plum.uimodels.render.swing.components.containers;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JComponent;
import javax.swing.JPanel;

import com.bluesky.plum.uimodels.standard.UIComponent;

public class SGridBagForm extends
		com.bluesky.plum.uimodels.standard.components.containers.form.Form {

	JPanel panel;

	public SGridBagForm() {
		panel = new JPanel();

		GridBagLayout layout = new GridBagLayout();
		panel.setLayout(layout);

	}

	@Override
	public void addChildComponent(UIComponent uic) {

		super.addChildComponent(uic);

		GridBagConstraints c = new GridBagConstraints();
		int newSize = getChildrenComponents().size()+1;
		c.gridx = newSize % 2;
		c.gridy = newSize / 2;

		panel.add((JComponent) uic.getNativeComponent(),c);
	}
	
	

	@Override
	public Object getNativeComponent() {

		return panel;
	}
}
